﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Things.Web.Components
{
    public partial class OrderGoodsList : System.Web.UI.UserControl
    {
        public Guid GoodsOrderID
        {
            get
            {
                string temp = hfGoodsOrderID.Value;
                Guid guid = Guid.Empty;
                if (Guid.TryParse(temp, out guid) == false)
                {
                    guid = Guid.Empty;
                }
                return guid;
            }
            set
            {
                hfGoodsOrderID.Value = value.ToString();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }

        protected void BindData()
        {
            Things.BLL.GoodsOrders goBLL = new BLL.GoodsOrders();
            DataSet ds = goBLL.GetGoodsListByGoodsOrderID(GoodsOrderID);

            gridView.DataSource = ds;
            gridView.DataBind();

            Things.Model.GoodsOrders goModel = goBLL.GetModel(GoodsOrderID);
            if (goModel != null && goModel.Status == Things.Common.ConstantString.GoodsOrderSatus.交易成功.ToString()) ;
            {
                hfOperationVisible.Value = "1";
            }
        }

        protected void gridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string strGUID = gridView.DataKeys[e.Row.DataItemIndex].Value.ToString();
                Guid guid = Guid.Empty;
                if (Guid.TryParse(strGUID, out guid) == true)
                {
                    GoodsOperation GoodsOperation1 = (GoodsOperation)e.Row.FindControl("GoodsOperation1");
                    GoodsOperation1.GoodsPriceID = guid;
                    GoodsOperation1.Visible = hfOperationVisible.Value == "1";
                }

            }
        }
    }
}